package com.jie.user.controller;

import com.jie.component.validation.annotion.Valid;
import com.jie.model.dto.user.UserRegisterWithPhoneDTO;
import com.jie.common.result.Result;
import com.jie.model.dto.user.UserRegisterWithPhoneSendCodeDTO;
import com.jie.user.service.UserRegisterService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jie
 * @version 1.0 2025-02-13
 */
@RestController
@RequestMapping("/register")
@RequiredArgsConstructor
public class UserRegisterController {

    private final UserRegisterService userRegisterService;

    /**
     * 手机号注册
     * @param userRegisterWithPhoneDTO
     * @return
     */
    @PostMapping("/phone")
    @Valid
    public Result<Void> registerWithPhone(@Valid @RequestBody UserRegisterWithPhoneDTO userRegisterWithPhoneDTO) {
        userRegisterService.registerWithPhone(userRegisterWithPhoneDTO);
        return Result.success();
    }

    @PostMapping("/code")
    @Valid
    public Result<Void> sendCode(@Valid @RequestBody UserRegisterWithPhoneSendCodeDTO userRegisterWithPhoneSendCodeDTO) {
        userRegisterService.sendCode(userRegisterWithPhoneSendCodeDTO);
        return Result.success();
    }
}
